package DBLayer;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class CityDB
{
    private  Connection conn;

    public CityDB()
    {
    	conn = ConnectionDB.getInstance().getDBcon();
    }
    
    /**
     * Return city name by zipcode.
     * @param zipcode	of the city.
     * @return	city name. Null if not exists.
     */
    public String getCity(int zipcode)
    {
    	String query = "select city from City where zipcode=" + zipcode;
    	String city = null;
    	
    	try
    	{
    		Statement stmt = conn.createStatement();
    		stmt.setQueryTimeout(5);
    		ResultSet set = stmt.executeQuery(query);
    		
    		if (set.next())
    		{
    			city = set.getString("city");
    		}
    		
    	}
    	catch (SQLException e)
    	{
    		
    	}
    	
    	return city;
    }
}
